﻿#region Using Directives

using System;
using System.Web.Security;
using System.Collections.Generic;

using QuickDev.Common.Serialization;
using QuickDev.Common.Utils;

using QuickDev.Model;
using QuickDev.SQLServerDAL;
using QuickDev.Caching;

#endregion

namespace QuickDev.BLL
{
    /// <summary>
    /// BLL Layer For dbo.SYS_Provider.
    /// </summary>
    public class ProviderBLL
    {
        #region ProviderBLL.IsExist( int providerTypeId , string name )
        /// <summary>
        /// public static bool IsExist( int providerTypeId , string name )
        /// </summary>
        /// <param name="providerTypeId">providerTypeId</param>
        /// <param name="name">name</param>
        /// <returns>bool Existed</returns>
        public static bool IsExist( int providerTypeId, string name )
        {
            Validation.ValidateIntegerIsGreaterThanZero( providerTypeId, "BirdleadsServices.BLL.ProviderBLL.IsExist() Method -- providerTypeId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( name, "BirdleadsServices.BLL.ProviderBLL.IsExist() Method -- name" );

            return ProviderDAL.IsExist( providerTypeId, name );
        }

        #endregion

        #region ProviderBLL.Add( int providerTypeId, string name, string description, string configurationControlPath, int createBy ) Method

        /// <summary>
        /// public static int Add( int providerTypeId, string name, string description, string configurationControlPath, int createBy )
        /// </summary>
        /// <param name="providerTypeId">providerTypeId</param>
        /// <param name="name">name</param>
        /// <param name="description">description</param>
        /// <param name="configurationControlPath">configurationControlPath</param>
        /// <param name="createdBy">createdBy</param>
        /// <returns>Provider model</returns>
        public static Provider Add( int providerTypeId, string name, string description, string configurationControlPath, int createBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( providerTypeId, "BirdleadsServices.BLL.ProviderBLL.Add() Method -- providerTypeId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( name, "BirdleadsServices.BLL.ProviderBLL.Add() Method -- name" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( configurationControlPath, "BirdleadsServices.BLL.ProviderBLL.Add() Method -- configurationControlPath" );

            int newProviderId = ProviderDAL.Add( providerTypeId, name, description, configurationControlPath, createBy );

            if ( newProviderId > 0 )
            {
                ProviderCache.RemoveAllCollectionFromCache();

                return ProviderCache.GetModel( newProviderId );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ProviderBLL.Update( int providerId, int providerTypeId, string name, string description, string configurationControlPath, int updateBy ) Method

        /// <summary>
        /// public static bool Update( int providerId, int providerTypeId, string name, string description, string configurationControlPath, int updateBy )
        /// </summary>
        /// <param name="providerId">providerId</param>
        /// <param name="providerTypeId">providerTypeId</param>
        /// <param name="name">name</param>
        /// <param name="description">description</param>
        /// <param name="configurationControlPath">configurationControlPath</param>
        /// <param name="updateBy">updateBy</param>
        /// <returns>Provider model</returns>
        public static Provider Update( int providerId, int providerTypeId, string name, string description, string configurationControlPath, int updateBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( providerId, "BirdleadsServices.BLL.ProviderBLL.Add() Method -- providerId" );
            Validation.ValidateIntegerIsGreaterThanZero( providerTypeId, "BirdleadsServices.BLL.ProviderBLL.Add() Method -- providerTypeId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( name, "BirdleadsServices.BLL.ProviderBLL.Add() Method -- name" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( configurationControlPath, "BirdleadsServices.BLL.ProviderBLL.Add() Method -- configurationControlPath" );

            if ( ProviderDAL.Update( providerId, providerTypeId, name, description, configurationControlPath, updateBy ) )
            {
                ProviderCache.RemoveAllCollectionFromCache();
                ProviderCache.RemoveModelFromCache( providerId );

                return ProviderCache.GetModel( providerId );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ProviderBLL.Update(int providerId, string status, int updateBy) Method

        /// <summary>
        /// public bool Update(int providerId, string status, int updateBy)
        /// </summary>
        /// <param name="providerId">providerId</param>
        /// <param name="status">status</param>
        /// <param name="updateBy">updateBy</param>
        /// <returns>Provider model</returns>
        public static Provider Update( int providerId, int status, int updateBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( providerId, "BirdleadsServices.BLL.ProviderBLL.Update -- providerId" );

            if ( ProviderDAL.Update( providerId, status, updateBy ) )
            {
                ProviderCache.RemoveAllCollectionFromCache();
                ProviderCache.RemoveModelFromCache( providerId );

                return ProviderCache.GetModel( providerId );
            }
            else
            {
                return null;
            }
        }
        #endregion
    }
}

